﻿using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MapEditor.Tiles;

namespace MapEditor.Tools
{
    class Brush : Tool
    {
        public Selection selectorTileset;

        public Brush(Selection selectorTileset)
        {
            this.selectorTileset = selectorTileset;
        }

        public override void Use(TileLayer layer, int tileX, int tileY, TileType tileType, int type, bool showGrid)
        {
            PaintArea(layer, tileX, tileY, tileType, type, showGrid);
        }

        public override void DrawRegularTilePreview(SpriteBatch spriteBatch, Texture2D tilesetTexture, Rectangle previewRect)
        {
            spriteBatch.Draw(tilesetTexture, previewRect, Color.White);
        }

        public override void DrawCustomTilePreview(SpriteBatch spriteBatch, Rectangle previewRect, TileType tileType)
        {
            Utility.DrawCustomTile(spriteBatch, previewRect, tileType);
        }

        public override Rectangle PreviewRect
        {
            get
            {
                return new Rectangle(Math.Max(Position.X / selectorTileset.TileSize * selectorTileset.TileSize, 0), Math.Max(Position.Y / selectorTileset.TileSize * selectorTileset.TileSize, 0), selectorTileset.Rectangle.Width, selectorTileset.Rectangle.Height);
            }
            
        }

        public override Rectangle PreviewRectNoGrid
        {
            get
            {
                return new Rectangle(Math.Max(Position.X, 0), Math.Max(Position.Y, 0), selectorTileset.Rectangle.Width, selectorTileset.Rectangle.Height);
            }
            
        }
    }
}